//
//  RecommendViewController.m
//  YYZB
//
//  Created by BY_R on 16/4/7.
//
//

#import "RecommendViewController.h"

#import "WeChatShareWebService.h"

static NSString * HTML = @"invite/index.html";

@interface RecommendViewController ()

@property (strong, nonatomic) WeChatShareWebService *webService;

@end

@implementation RecommendViewController

- (WeChatShareWebService *)webService {
    if (!_webService) {
        _webService = WeChatShareWebService.new;
    }
    
    return _webService;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"推荐有礼";
    self.HTMLURL = HTML;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shareFinished:) name:@"NotificationNameShareFinished" object:nil];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"NotificationNameShareFinished" object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)shareFinished:(NSNotification *)notification {
    NSDictionary *userInfo = notification.object;
    BOOL result = NO;
    if (userInfo[@"code"] && [userInfo[@"code"] integerValue] == 0) {
        result = YES;
    }
    [self.webService uploadShareResultByID:[UserInfoController WeChatShareID] type:@"1" userId:[UserInfoController userID] result:YES completionHanlder:^(NSArray *items, NSError *error) {
        if (error) {
            NSLog(@"%@", [error localizedDescription]);
        }
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
